package com.itheima.reggie.common;

import com.itheima.reggie.entity.Employee;
import com.itheima.reggie.entity.User;

/*
*     工具栏  保存用户id
* */
public class BaseContext {

    private static final ThreadLocal<Long> threadLocal =new ThreadLocal<>();

    /*
    * 设置id
    * */
    public static void setCurrentId(Long id){
        threadLocal.set(id);
    }
    /*
    * 获取id
    * */
    public static Long getCurrentId(){
        return threadLocal.get();
    }
    /*
    *   获取对象
    * */
    public static Object getCurrentUser(Object o){
        if (o instanceof User){
            return ((User) o).getName();
        }
        if (o instanceof Employee){
            return ((Employee) o).getName();
        }
        return o;
    }

    /*
    *   释放
    * */
    public static void release(){
        threadLocal.remove();
    }
}
